package net.wanho.shop.controller;


import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.wanho.shop.dto.LoginLogDTO;
import net.wanho.shop.po.LoginLog;
import net.wanho.shop.service.LoginLogService;
import net.wanho.shop.vo.AjaxResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;


/**
 * <p>
 * 系统登录日志 前端控制器
 * </p>
 *
 * @author 猛虎王
 * @since 2024-12-24
 */
@Api(tags = "13.2系统登录日志接口")
@RestController
@RequestMapping("/login-log")
@RequiredArgsConstructor
public class LoginLogController {

    private final LoginLogService loginLogService;

    @ApiOperation("系统登录日志分页查询")
    @GetMapping
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pageNum,
                               @ApiParam("页大小") @RequestParam(defaultValue = "5") int pageSize,
                               @ApiParam("查询条件") LoginLogDTO loginLogDTO) {
        PageInfo<LoginLog> pageInfo = loginLogService.findPage(pageNum, pageSize, loginLogDTO);
        return AjaxResult.success(pageInfo);
    }

    @ApiOperation("根据主键查询系统登录日志")
    @GetMapping("/{infoId}")
    public AjaxResult findById(@PathVariable Serializable infoId) {
        return AjaxResult.success(loginLogService.findById(infoId));
    }

    @ApiOperation("新增系统登录日志")
    @PostMapping
    public AjaxResult add(@RequestBody LoginLog loginLog) {
        loginLogService.add(loginLog);
        return AjaxResult.success();
    }

    @ApiOperation("修改系统登录日志")
    @PutMapping
    public AjaxResult modify(@RequestBody LoginLog loginLog) {
        loginLogService.modify(loginLog);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除系统登录日志")
    @DeleteMapping("/{infoId}")
    public AjaxResult removeById(@PathVariable Serializable infoId) {
        loginLogService.removeById(infoId);
        return AjaxResult.success();
    }

}
